


window.buangParent = Jx.Class.instantiate('Jx.event.Observable');

window.buang = Jx.Class.instantiate('Jx.event.Observable');

buang.event.setBubbleTarget( buangParent );

buang.event.listen({

	'buang': function(evt){

		console.log('buang eventobject ', evt);

	}

});



buangParent.event.listen({

	'buang': function(evt){

		console.log('buangParent eventobject ', evt);

		buangParent.event.unlisten('buang', arguments.callee);

	},

	':defer': 500

});


window.query = Jx.instantiate('Jx.dom.css.Query');



window.trace = function(use, path, returnValue, showLength){

	var startTime = (new Date()).getTime(),

		returned = void(0);

	switch(use){

		case 'Ext':

			returned = Ext.DomQuery.jsSelect(path);

			break;

		case 'Browser':

			returned = document.querySelectorAll(path) || [];

			break;

		default:

			query.trace = false;

			returned = query.select(path, document) || [];

			break;

	}

	console.log(use+' runtime: '+( ((new Date()).getTime() - startTime) / 1000 )+' seconds');

	if (showLength){

		console.log('found: ', returned.length );

	}

	return returnValue ?

		returned

		:

		void(0);

}

window.traceJx = function( path ){

	return trace.apply( this, [ 'Jx' ].concat(

		Array.prototype.slice.call( arguments, 0 )

	));

}

window.traceExt = function( path ){

	return trace.apply( this, [ 'Ext' ].concat(

		Array.prototype.slice.call( arguments, 0 )

	));

}

window.traceDefault = function( path ){

	return trace.apply( this, [ 'Browser' ].concat(

		Array.prototype.slice.call( arguments, 0 )

	));

}







window.recurseSubject = {

	name: 'root',

	children: [{

		name: 'child[1]',

		children: [{

			name: 'child[1][1]',

			children: []

		},{

			name: 'child[1][2]',

			children: []

		}]

	}, {

		name: 'child[2]',

		children: [{

			name: 'child[2][1]',

			children: []

		},{

			name: 'child[2][2]',

			children: []

		}]

	}, {

		name: 'child[3]',

		children: [{

			name: 'child[3][1]',

			children: []

		}]


	}]

};


window.recurseFunc = function( subject ){

	var children = [ subject ],

		stack = [],

		stackCount = 0;

	var currentStack,

		child, childChildren, childLength;

	for(var index=-1, l = 1; l--;){

		child = children[ ++index ];

		console.log('  = preprocess: ', child.name );

		childChildren = child.children;

		childLength = childChildren.length;

		/* push */
		if (childLength){

			stack[ stackCount++ ] = [ children, index, l ];

			console.log(' + pushed: ', child.name );

			children = childChildren;

			index = -1;

			l = childLength;

		} else {

			console.log('  = process ', child.name);

			/* pop */
			for(; !l && stackCount-- ;){

				currentStack = stack[ stackCount ];

				stack.length = stackCount;

				children = currentStack[0];

				index = currentStack[1];

				l = currentStack[2];

				console.log(' - pop: ', children[ index ].name);

				console.log('  = process ', children[ index ].name);

			}

		}

	}

	console.log('stack: ', stack)

}

window.recurseCall = function(){

	recurseFunc( recurseSubject );

}





//buangFn = function(){
//
//}
